package com.discovery.core.annotation.json;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author xuebinlu
 * @Date 2018/5/28 11:12
 * @Version 1.0
 * @Description Jackson 返回的json字符串配置
 **/
@Component
public class JackJsonHttpMessageConverterEx extends MappingJackson2HttpMessageConverter {

    public JackJsonHttpMessageConverterEx() {
        super();
        ObjectMapper objectMapper = this.getObjectMapper();
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    }

    @Override
    protected boolean supports(Class<?> clazz) {
        return super.supports(clazz);
    }

    @Override
    protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
        super.writeInternal(o, outputMessage);
    }
}
